<template>
  <div class="el-full el-box-column">
    <el-card class="box-card el-card-flex">
      <div slot="header" class="clearfix">
        <span>
          <i class="el-icon-warning-outline"></i>
          {{formTitle}}
        </span>
      </div>
      <div class="text item el-over-auto">
        <el-form label-width="150px" ref="formData" :model="formData">
          <el-form-item label="任务类型：" prop="taskCat" :rules="[
              {
                required: true,
                message: '请选择任务类型'
              }
            ]">
            <el-col :span="8">
              <el-select v-model="formData.taskCat" placeholder="请选择任务类型">
                <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="任务编码：" prop="taskCode">
            <el-col :span="8">
              <el-input v-model="formData.taskCode" :disabled="true" placeholder="系统自动生成"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="要求完成时间：" prop="expirationDate" :rules="{type: 'date', required: true, message: '请选择日期', trigger: 'change'}">
            <el-col :span="6">
              <el-date-picker type="date" v-model="formData.expirationDate" placeholder="选择日期" :picker-options='pickerBeginDateBefore'></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="任务内容：" prop="taskContent" :rules="[
              {
                required: true,
                message: '请输入任务内容'
              }
            ]">
            <el-col :span="12">
              <el-input placeholder="请输入任务内容" v-model="formData.taskContent" type="textarea"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="备注：" prop="taskDesc">
            <el-col :span="12">
              <el-input placeholder="请输入备注" v-model="formData.taskDesc" type="textarea"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="发布人：" prop="issuerUserId" :rules="{ required: true, message: '请选择发布人',trigger: 'change'}">
            <el-col :span="6">
              <el-input placeholder="请选择发布人" v-model="formData.issuer" readonly>
                <i v-show="formData.issuer && upTaskId==''" slot="suffix" @click="clearissuerName" style="cursor: pointer;"></i>
                <el-button slot="append" icon="el-icon-search" @click="issuerPeople" v-if="!upTaskId"></el-button>
              </el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="发布日期：" prop="issueDate" :rules="{type: 'date', required: true, message: '请选择日期', trigger: 'change'}">
            <el-col :span="6">
              <el-date-picker type="date" v-model="formData.issueDate" placeholder="选择日期" :picker-options='pickerBeginDateBefore'></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="责任人：" prop="principalUserId" :rules="[
              {
                required: true,
                message: '请选择责任人',
                trigger: 'change'
              }
            ]">
            <el-col :span="6">
              <el-input placeholder="请选择责任人" v-model="formData.principal" readonly>
                <i v-show="formData.principal" slot="suffix" @click="clearprincipalName" style="cursor: pointer;"></i>
                <el-button slot="append" icon="el-icon-search" @click="principalPeople"></el-button>
              </el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="协助人：" prop="assistPerson">
            <el-col :span="12">
              <el-input placeholder="请选择协助人" v-model="formData.assistPerson" readonly>
                <i v-show="formData.assistPerson" slot="suffix" @click="clearassistName" class="el-input__icon el-icon-circle-close"
                  style="cursor: pointer;"></i>
                <el-button slot="append" icon="el-icon-search" @click="assistPeople"></el-button>
              </el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="知会人：" prop="notifyPerson">
            <el-col :span="12">
              <el-input placeholder="请选择知会人" v-model="formData.notifyPerson" readonly>
                <i v-show="formData.notifyPerson" slot="suffix" @click="clearnotifyName" class="el-input__icon el-icon-circle-close"
                  style="cursor: pointer;"></i>
                <el-button slot="append" icon="el-icon-search" @click="notifyPeople"></el-button>
              </el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="附件：">
            <el-col :span="7">
              <el-upload action="/api/ccms/attachment/uploadByBusiness" :on-preview="handlePreview" :before-remove="beforeRemove"
                :on-remove="onRemove" multiple :limit="10" :data="fileData" :on-exceed="handleExceed" :file-list="fileList"
                ref="upload" :on-change="onChangeFile" :on-success="onSuccess" :on-error="onError" :auto-upload="false"
                :before-upload="beforeAvatarUpload" :headers="{Authorization: this.Authorization}">
                <el-button size="small" type="primary">选择文件</el-button>
              </el-upload>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div style="text-align: right;margin-bottom: 8px;margin-right: 8px;">
        <el-button type="primary" @click="handleCheckStag('formData')">暂存 <i class="el-icon-document-checked"></i>
        </el-button>
        <el-button type="primary" @click="handleCheckRelease('formData')">发布 <i class="el-icon-position"></i>
        </el-button>
        <el-button type="danger" @click="cancelEvt">关闭 <i class="el-icon-close"></i>
        </el-button>
      </div>
    </el-card>
    <!-- 发布人 -->
    <selectPersonnelDalog :dialogPersonnelVisible="dialogissuerVisible" :multiple="false" :schedulePersonList="issuerDatas"
      @dialogEmployeesData="dialogissuerCheckSure" />
    <!-- 责任人 -->
    <selectPersonnelDalog :dialogPersonnelVisible="dialogprincipalVisible" :schedulePersonList="principalDatas"
      :schedulePersonData='this.$route.params.row.assistPersonList' :dialogModalTitle='dialogModalTitle'
      :schedulePersonTab='upTaskId' :multiple="false" @dialogEmployeesData="dialogprincipalCheckSure" />
    <!-- 协助人 -->
    <selectPersonnelDalog :schedulePersonList="formData.assistPersonList" :dialogPersonnelVisible="dialogassistVisible"
      :multiple="true" @dialogEmployeesData="dialogassistCheckSure" />
    <!-- 知会人notify -->
    <selectPersonnelDalog :schedulePersonList="formData.notifyPersonList" :dialogPersonnelVisible="dialognotifyVisible"
      :multiple="true" @dialogEmployeesData="dialognotifyCheckSure" />
  </div>
</template>
<script>
  import {
    Dialog,
    Table,
    TableColumn,
    Pagination,
    MessageBox,
    Message,
    Drawer,
    Tabs,
    TabPane,
    Upload
  } from 'element-ui'
  import {
    comboBoxData, //任务类型
    taskAdd, //暂存新增
    taskUpdata, //暂存修改
    getTaskData, //获取详情
    taskStatus, //发布
    findAttchList, //获取文件
    removeFiles, //附件删除
  } from '@/api/missionCenter/missionCenter.js'
  import selectPersonnelDalog from "./selectPeopleOther"
  export default {
    name: "createTask",
    components: {
      'el-dialog': Dialog, // 对话框
      'el-table': Table, // 表格
      'el-table-column': TableColumn, // 表格列
      'el-pagination': Pagination, // 分页
      'el-drawer': Drawer, // 抽屉
      'el-tabs': Tabs, // 标签页
      'el-tab-pane': TabPane, // 标签页列
      "el-upload": Upload, //上传
      selectPersonnelDalog
    },
    data() {
      var dataList = {}
      return {
        pickerBeginDateBefore: {
          disabledDate(date) {
            return date.getTime() <= Date.now() - 8.64e7;
          }
        },
        issuerDatas: [],
        principalDatas: [],
        dialogModalTitle: '',
        schedulePersonTab: false,
        formTitle: '',
        Authorization: '', // 获取系统Authorization
        dialogissuerVisible: false, // 选择人员弹框显示
        dialogprincipalVisible: false, //选择责任人弹框
        dialogassistVisible: false, //选择协助人
        dialognotifyVisible: false, //notify知会人
        options: [],
        value: '',
        publish: '',
        formData: {
          taskId: '',
          taskCat: '',
          taskCode: '',
          expirationDate: '',
          taskContent: '',
          taskDesc: '',
          issuer: '',
          issuerUserId: '',
          issueDate: '',
          principal: '',
          principalUserId: '',
          assistPersonList: [],
          notifyPersonList: [],
          notifyPerson: '',
          assistPerson: '',
        },
        fileData: {
          bigCatName: '',
          smallCatName: '',
          businessId: ''
        },
        fileList: [],
        enclosures: JSON.parse(JSON.stringify(dataList)),
        upTaskId: '',
      }
    },
    created() {
      this.getComboBoxData()
      this.formTitle = '创建任务'
      if (this.$route.params.row == 'object' || typeof this.$route.params.row == 'object') {
        this.upTaskId = this.$route.params.row.taskId
        this.formData.issuer = this.$route.params.row.principal
        this.formData.issuerUserId = this.$route.params.row.principalUserId
        this.formTitle = '创建任务'
      } else {
        this.taskTabel(this.$route.params.row)
        this.formTitle = '编辑任务'
      }
      this.Authorization = this.getCookie('Authorization')
      this.fileData.sysCode = this.getCookie('sysCode')
    },
    methods: {
      getCookie(cname) {
        var name = cname + "="
        var ca = document.cookie.split(';')
        for (var i = 0; i < ca.length; i++) {
          var c = ca[i].trim()
          if (c.indexOf(name) == 0) return c.substring(name.length, c.length)
        }
        return ""
      },
      //任务类型
      getComboBoxData() {
        comboBoxData('8c5a8d89d5d143c79e5a192082e7ead8').then((res) => {
          if (res.data.code == 10000) {
            this.options = res.data.data
          }
        })
      },
      //获取详情
      taskTabel(id) {
        getTaskData(id).then((res) => {
          if (res.data.code == 10000) {
            this.formData = res.data.data
            this.formData.issueDate = new Date(this.formData.issueDate)
            this.formData.expirationDate = new Date(this.formData.expirationDate)
            let assistNameList = []
            this.formData.assistPersonList.forEach(e => {
              e.empName = e.personName
              assistNameList.push(e.empName)
            })
            this.formData.assistPerson = assistNameList.join(' ')

            let notifyNameList = []
            this.formData.notifyPersonList.forEach(e => {
              e.empName = e.personName
              notifyNameList.push(e.empName)
            })
            this.formData.notifyPerson = notifyNameList.join(' ')
            findAttchList({
              businessId: id,
              smallCatName: '附件'
            }).then((res) => {
              if (res.data.code == 10000) {
                this.fileList = res.data.data.records
                this.fileList.forEach(e => {
                  e.name = e.attFullName
                })
              }
            })
          }
        })
      },
      cancelEvt() {
        this.$router.go(-1)
      },
      //删除确认
      beforeRemove(file, fileList) {
        return MessageBox.confirm(`确定移除 ${ file.name }？`)
      },
      //点击文件获取文件信息
      handlePreview(file) {
        if (!file.attId) return
        // 自定义form标签，初始化相关参数
        var form = document.createElement("form")
        // var access_token = "d54e3ef7-6d69-4b4e-afb3-ef539cb80f9b"
        form.setAttribute("style", "display:none")
        form.setAttribute("method", "post")
        var params = {}
        // params.Authorization = access_token
        form.setAttribute("header", params)
        // var path = 'E:\\_ex_workplace\\zxsbWeb\\esgov-zxsb-zxsbweb\\src\\pages\\selfDetection.vue'
        var input = document.createElement('input')
        input.setAttribute('type', 'hidden')
        input.setAttribute('name', 'attId')
        input.setAttribute('value', file.attId)
        form.append(input)
        form.setAttribute("action", "/api/ccms/attachment/download")
        // form.setAttribute("target", "_blank")
        var body = document.createElement("body")
        body.setAttribute("style", "display:none")
        document.body.appendChild(form)
        form.submit()
        form.remove()

      },
      //控制文件个数
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 10 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
      },
      beforeAvatarUpload(file) {
        if (!file) {
          Message.warning("请选择需要导入的模板！")
          return
        }
      },
      // 上传的文件的列表发生变化
      onChangeFile(file, fileList) {
        this.fileList = fileList
      },
      onSuccess(res) {
        // console.log(res)
        if (res.code === 10000) {
          this.$router.go(-1)
        } else {
          Message.success(res.msg)
        }
      },
      // 文件上传(提交)接口失败
      onError(err) {
        Message.error('上传失败')
        console.log('失败', err)
      },
      onRemove(file, fileList) { //附件删除
        if (!file.attId) {
          Message.success('附件移除成功')
        } else {
          removeFiles(file.attId).then(res => {
            if (res.data.code == 10000) {
              Message.success('附件移除成功')
            }
          })
        }
      },
      //暂存
      handleCheckStag(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) { //校验
            var newD = new Date(this.formData.expirationDate)
            var y = newD.getFullYear()
            var m = newD.getMonth() + 1
            var d = newD.getDate()
            if (m < 10) {
              m = '0' + m
            }
            if (d < 10) {
              d = '0' + d
            }
            var newD1 = new Date(this.formData.issueDate)
            var y1 = newD1.getFullYear()
            var m1 = newD1.getMonth() + 1
            var d1 = newD1.getDate()
            if (m1 < 10) {
              m1 = '0' + m1
            }
            if (d1 < 10) {
              d1 = '0' + d1
            }
            if (!this.upTaskId) {
              if (!this.formData.taskId) {
                taskAdd({ //数据请求
                  'taskCat': this.formData.taskCat,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "directIssue": 'N'
                }).then(res => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "暂存成功"
                    })
                    this.$router.go(-1)

                  }
                })
              } else {
                taskUpdata({
                  'taskCat': this.formData.taskCat,
                  "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "taskId": this.formData.taskId,
                  "directIssue": 'N'
                }).then((res) => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "暂存成功"
                    })
                    this.$router.go(-1)
                  }
                })
              }
            } else {
              if (!this.formData.taskId) {
                taskAdd({ //数据请求
                  'taskCat': this.formData.taskCat,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "upTaskId": this.upTaskId,
                  "directIssue": 'N'
                }).then(res => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "暂存成功"
                    })
                    this.$router.go(-1)

                  }
                })
              } else {
                taskUpdata({
                  'taskCat': this.formData.taskCat,
                  "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "taskId": this.formData.taskId,
                  "upTaskId": this.upTaskId,
                  "directIssue": 'N'
                }).then((res) => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "暂存成功"
                    })
                    this.$router.go(-1)
                  }
                })
              }
            }
          }
        });
      },
      //发布
      handleCheckRelease(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) { //校验
            var newD = new Date(this.formData.expirationDate)
            var y = newD.getFullYear()
            var m = newD.getMonth() + 1
            var d = newD.getDate()
            if (m < 10) {
              m = '0' + m
            }
            if (d < 10) {
              d = '0' + d
            }
            var newD1 = new Date(this.formData.issueDate)
            var y1 = newD1.getFullYear()
            var m1 = newD1.getMonth() + 1
            var d1 = newD1.getDate()
            if (m1 < 10) {
              m1 = '0' + m1
            }
            if (d1 < 10) {
              d1 = '0' + d1
            }
            if (!this.upTaskId) {
              if (!this.formData.taskId) {
                // taskId:'',
                taskAdd({ //数据请求
                  'taskCat': this.formData.taskCat,
                  // "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "directIssue": 'Y'
                }).then(res => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "发布成功"
                    })
                    this.$router.go(-1)
                  }
                })
              } else {
                taskUpdata({
                  'taskCat': this.formData.taskCat,
                  "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "taskId": this.formData.taskId,
                  "directIssue": 'Y'
                }).then((res) => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "发布成功"
                    })
                    this.$router.go(-1)
                  }
                })
              }
            } else {
              if (!this.formData.taskId) {
                // taskId:'',
                taskAdd({ //数据请求
                  'taskCat': this.formData.taskCat,
                  // "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "directIssue": 'Y',
                  "upTaskId": this.upTaskId,
                }).then(res => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "发布成功"
                    })
                    this.$router.go(-1)
                  }
                })
              } else {
                taskUpdata({
                  'taskCat': this.formData.taskCat,
                  "taskCode": this.formData.taskCode,
                  "expirationDate": y + '-' + m + '-' + d,
                  "taskContent": this.formData.taskContent,
                  "taskDesc": this.formData.taskDesc,
                  "issuer": this.formData.issuer,
                  "issuerUserId": this.formData.issuerUserId,
                  "issueDate": y1 + '-' + m1 + '-' + d1,
                  "principal": this.formData.principal,
                  "principalUserId": this.formData.principalUserId,
                  "assistPersonList": this.formData.assistPersonList,
                  "notifyPersonList": this.formData.notifyPersonList,
                  "orgId": '0',
                  "taskId": this.formData.taskId,
                  "directIssue": 'Y',
                  "upTaskId": this.upTaskId,
                }).then((res) => {
                  if (res.data.code == 10000) {
                    this.fileData.bigCatName = '任务管理'
                    this.fileData.smallCatName = '附件'
                    this.fileData.businessId = res.data.data.taskId
                    if (this.fileList.length !== 0) {
                      this.$refs.upload.submit()
                    }
                    Message({
                      type: 'success',
                      message: "发布成功"
                    })
                    this.$router.go(-1)
                  }
                })
              }
            }
          }
        });
      },
      issuerPeople() { //发布人弹框
        this.dialogissuerVisible = true;
      },
      dialogissuerCheckSure(data) {
        this.dialogissuerVisible = false
        if (!data) {
          return
        }
        this.issuerDatas = JSON.parse(JSON.stringify(data))
        if (data.length == 0) {
          this.formData.issuerUserId = ''
          this.formData.issuer = ''
        } else {
          this.formData.issuerUserId = data[0].userId
          this.formData.issuer = data[0].empName
          if (data[0].empName == this.formData.principal) {
            return Message({
              type: 'warning',
              message: "发布人不可与责任人一致"
            })
          }
        }
      },
      clearissuerName() {
        this.formData.issuer = ''
        this.formData.issuerUserId = ''
      },
      //责任人弹框
      principalPeople() {
        this.dialogprincipalVisible = true;
        this.dialogModalTitle = '责任人'
        if (this.upTaskId == '') {
          this.upTaskId = null
        }
      },
      dialogprincipalCheckSure(data) {
        this.dialogprincipalVisible = false
        if (!data) {
          return
        }
        this.principalDatas = JSON.parse(JSON.stringify(data))
        if (data.length == 0) {
          this.formData.principalUserId = ''
          this.formData.principal = ''
        } else {
          this.formData.principalUserId = data[0].userId
          this.formData.principal = data[0].empName
          if (data[0].empName == this.formData.issuer) {
            return Message({
              type: 'warning',
              message: "责任人不可与发布人一致"
            })
          }
        }
      },
      clearprincipalName() {
        this.formData.principal = ''
        this.formData.principalUserId = ''
      },
      //
      //协助人弹框
      assistPeople() {
        this.dialogassistVisible = true;
      },
      dialogassistCheckSure(data) {
        this.dialogassistVisible = false
        if (!data) {
          return
        }
        this.formData.assistPersonList = JSON.parse(JSON.stringify(data))
        let assistNameList = []
        data.forEach(e => {
          e.personName = e.empName
          assistNameList.push(e.personName)
          if (this.formData.issuer == e.empName || this.formData.principal == e.empName) {
            return Message({
              type: 'warning',
              message: "协助人不可与发布人或责任人一致"
            })
          }
        })
        this.formData.assistPerson = assistNameList.join(' ')
        this.formData.assistPersonList.forEach(e => {
          e.personUserId = e.userId
          e.personName = e.empName
        })
      },
      clearassistName() {
        this.formData.assistPersonList = []
        this.formData.assistPerson = ''
      },
      //知会人
      notifyPeople() {
        this.dialognotifyVisible = true;
      },
      dialognotifyCheckSure(data) {
        this.dialognotifyVisible = false
        if (!data) {
          return
        }
        data = JSON.parse(JSON.stringify(data))
        this.formData.notifyPersonList = data
        let notifyNameList = []
        data.forEach(e => {
          e.personName = e.empName
          notifyNameList.push(e.personName)
          if (this.formData.issuer == e.empName || this.formData.principal == e.empName) {
            return Message({
              type: 'warning',
              message: "知会人不可与发布人或责任人一致"
            })
          }
        })
        this.formData.notifyPerson = notifyNameList.join(' ')
        this.formData.notifyPersonList.forEach(e => {
          e.personUserId = e.userId
          e.personName = e.empName
        })
      },
      clearnotifyName() {
        this.formData.notifyPersonList = []
        this.formData.notifyPerson = ''
      },
      handlePriview(file) { //预览

      }
    }
  }
</script>
